package com.bwie.home.backstage.service.impl;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.home.common.utils.PageUtils;
import com.bwie.home.common.utils.Query;

import com.bwie.home.backstage.dao.MetroDao;
import com.bwie.home.backstage.entity.MetroEntity;
import com.bwie.home.backstage.service.MetroService;


@Service("metroService")
public class MetroServiceImpl extends ServiceImpl<MetroDao, MetroEntity> implements MetroService {

    @Override
    public PageUtils queryPage(Map<String, Object> params, MetroEntity metro) {
        QueryWrapper<MetroEntity> wrapper = new QueryWrapper<>();
        if (metro != null) {
            if (metro.getProvinceName() != null && !metro.getProvinceName().equals("")) {
                wrapper.eq("province_name", metro.getProvinceName());
            }
            if (metro.getCityName() != null && !metro.getCityName().equals("")) {
                wrapper.eq("city_name", metro.getCityName());
            }
            if (metro.getMetroName() != null && !metro.getMetroName().equals("")) {
                wrapper.like("metro_name", metro.getMetroName());
            }
        }

        IPage<MetroEntity> page = this.page(
                new Query<MetroEntity>().getPage(params),
                wrapper
        );

        //获取区域
        List<MetroEntity> records = page.getRecords();
        for (MetroEntity record : records) {
            record.setAddress(record.getProvinceName() + "-" + record.getCityName());
        }
        page.setRecords(records);
        return new PageUtils(page);
    }

}